function selectURL(url, width, height, alt, link, link_target, styles, align, swf) {
	if(window.opener) {
		//url, width, height, alt
		if(swf == true) {
			window.opener.SetUrl(link, width, height);
		}
		else {
			window.opener.SetUrl( url, width, height, alt );
			if (window.opener.GetE('txtLnkUrl')) {
				window.opener.GetE('txtLnkUrl').value = link ;
			}
			if (window.opener.GetE('cmbLnkTarget')) {
				window.opener.GetE('cmbLnkTarget').value = link_target ;
			}
			if (window.opener.GetE('txtTargetFrame')) {
				window.opener.GetE('txtTargetFrame').value = link_target ;
			}
			
			if (window.opener.GetE('cmbTarget')) {
				window.opener.GetE('cmbTarget').value = link_target ;
			}
			if (window.opener.GetE('txtAttClasses')) {
				if(window.opener.GetE('txtAttClasses').value === '') {
					window.opener.GetE('txtAttClasses').value = 'uploaded-file';
				}
				else {
					window.opener.GetE('txtAttClasses').value = 'uploaded-file '+styles;
				}
			}
			if(window.opener.GetE('cmbAlign')) {
				window.opener.GetE('cmbAlign').value = align ;
			}
		}
		window.close();
	}
}
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}
$(document).ready(function() {
	equalHeight($('.img-browser'));
});
$(".insert").live('click', function() {
	if($("#swf").val() === 'true') {
		link = $("#url").val();
		width = $("#width").val();
		height = $("#height").val();
		selectURL(null, width, height, null, link, null, null, null, true);
	}
	else if($('#file').val() === 'true') {
		if($("#tb_image_preset").val() === "") {
			alert("Please select an image preset first.");
			return false;
		}
		var url = $("#tb_image_preset").val();
		
		
		if($("#tb_link_options").val() == 'custom') {
			var url = $("#tb_link_custom").val();
		}
		else {
			var url = $("#tb_link_options").val();
		}
		
		var link_target = $("#tb_link_target").val();
		

		selectURL(url, null, null, null, link, link_target, null, null, null);
		
	}
	else {
		if($("#tb_image_preset").val() === "") {
			alert("Please select an image preset first.");
			return false;
		}
		
		var url = $("#tb_image_preset").val();
		
		var alt = $("#fname").val();
		
		if($("#tb_link_options").val() == 'custom') {
			var link = $("#tb_link_custom").val();
		}
		else {
			var link = $("#tb_link_options").val();
		}
		
		var link_target = $("#tb_link_target").val();
		
		var align = $("#tb_alignment").val();
		var styles = 'img-aligned-' + align;

		selectURL(url, null, null, alt, link, link_target, styles, align, null);
	}
	return false;
});